class_name MinimapViewport
extends SubViewport

@onready var camera_node: Camera2D = %MiniCamera
var player_node : Node2D


func _ready() -> void:
	world_2d = get_tree().root.world_2d
	get_tree().root.set_canvas_cull_mask_bit(1,false)
	GameEvents.camera_follow_player.connect(_follow_player)


func _follow_player(player_position:Vector2):
	
	if camera_node.position.x - player_position.x > 200:
		camera_node.position.x = camera_node.position.x - 3 
		
	if camera_node.position.x - player_position.x < -200:
		camera_node.position.x = camera_node.position.x + 3
	
	if camera_node.position.y - player_position.y > 100:
		camera_node.position.y = camera_node.position.y - 3
	
	if camera_node.position.y - player_position.y < -100:
		camera_node.position.y = camera_node.position.y + 3
	#position = player_position


#func _process(delta: float) -> void:
	#camera_node.position = player_node.position
